import { reactive } from "vue";

export function configHook() {
    const config = reactive({
        selection: true,   //配置复选框
        batch_delete: true,//批量删除按钮
        pagination: true,  //分页
        creatProject: true,//创建项目
        expand: true,//表格展开
        search: true,
        row_key: "projectid",
        has_button_delete: "",
        has_button_batch_delete: "",
        expand_all: false,
        action_request: false,

    })
    /**
      * 
      * @param {*} data 配置额外组件，true显示，false不显示
      */
    const configInit = (data = {}) => {
        // 无数据时不执行
        if (JSON.stringify(data) === "{}") { return false; }
        // 获取默认配置项的所有key
        const keys = Object.keys(config);
        // 循环传入的配置项
        for (let key in data) {
            // 过滤原型链的对象
            if (!data.hasOwnProperty(key)) { continue; }
            // ES6语法判断传入的key和默认配置的key相同时，则直接更新默认配置项的值
            if (keys.includes(key)) { config[key] = data[key]; }
        }
    }
    return {
        config,
        configInit,
    }
}